package com.example.nbshopping.login;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.nbshopping.MainActivity;
import com.example.nbshopping.R;
import com.example.nbshopping.setting.SafetyActivity;
import com.example.nbshopping.utils.SaveUserUtils;

public class SettingActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView setting_iv_back;
    private TextView setting_tv_info,setting_tv_safety,setting_tv_pay;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
        setListener();
    }

    private void setListener() {
        setting_iv_back.setOnClickListener(this);
        setting_tv_info.setOnClickListener(this);
        setting_tv_safety.setOnClickListener(this);
        setting_tv_pay.setOnClickListener(this);
    }


    private void initView() {
        setting_iv_back=findViewById(R.id.setting_iv_back);
        setting_tv_info=findViewById(R.id.setting_tv_info);
        setting_tv_safety=findViewById(R.id.setting_tv_safety);
        setting_tv_pay=findViewById(R.id.setting_tv_pay);
    }

    //判断是否登录，如果登录就跳转到个人中心页面,如果没有登录，就跳转到登录页面
    private void islogin(int flag) {
        UserBean.DataBean userInfo = SaveUserUtils.getUserInfo(this);
        if (userInfo==null) {
            Intent it1 = new Intent(SettingActivity.this,LoginRegActivity.class);
            it1.putExtra("flag",flag);
            startActivity(it1);
        }else {
            Intent intent = new Intent(this, PersonCenterActivity.class);
            startActivity(intent);
        }
    }
    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.setting_iv_back:
                finish();
                break;
            case R.id.setting_tv_info:
                islogin(0);
                break;
            case R.id.setting_tv_safety:
                Intent intent=new Intent(this, SafetyActivity.class);
                startActivity(intent);
                break;
        }
    }
}